package com.ziyucoding.springboot.labs.lab3.rocketmqdemo.consumer;

import com.ziyucoding.springboot.labs.lab3.rocketmqdemo.message.Demo4Message;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 示例4的消费者（用于消费重试）
 *
 * @author ziyucoding
 * @date 2022-10-24
 **/
@Component
@RocketMQMessageListener(topic = Demo4Message.TOPIC, consumerGroup = "demo4-consumer-group-" + Demo4Message.TOPIC
)
public class Demo4Consumer implements RocketMQListener<Demo4Message> {

    private Logger logger = LoggerFactory.getLogger(Demo4Message.class);

    @Override
    public void onMessage(Demo4Message message) {
        logger.info("[onMessage][线程编号：{} 消息内容：{}]", Thread.currentThread().getId(), message);
        throw new RuntimeException("故意抛出异常，用于消费重试测试");
    }
}
